$(function () {
    //如果使用数据字典可以在这里发送ajax请求去查询返回用变量接收在下面去使用

    $("#productInfo_datagrid").datagrid({
        url: '/product/selectProductList',
        title: '已购产品列表',
        width: 300,
        columns: [[
            {field: 'name', title: '险种', width: 130},
            {field: 'money', title: '险种金额', width: 130}
        ]]
    });
   $("#payResult_datagrid").datagrid({
       url:'/paymentResult/query',
       fit:true,
       toolbar:'#payResult_toolbar',
       fitColumns:true,
       rownumbers:true,
       singleSelect:true,
       pagination:true,
       columns:[[
           /*{field:'id',checkbox:true},*/
           {field:'policyClient', title:'投保人', width:80, formatter:function (value) {
                        if(value){
                            return value.name;
                        }
                    }
               },
           {field:'number', title:'核保单号', width:80},
           {field:'totalPrice', title:'保费金额', width:80},
           {field:'limitYear', title:'保险年限(/年)', width:80},
           {field:'payWayId', title:'缴费方式', width:80, formatter:function (value, row, index) {
               if(value == 0){
                   return "现金";
               }
               if(value == 1){
                   return "支付宝";
               }
               if(value == 2){
                   return "微信";
               }
               if(value == 3){
                   return "银行卡";
               }
               if(value == 4){
                   return "卖身";
               }
           }},
           {field:'beginDate', title:'起保日期', width:80},
           {field:'endDate', title:'止保日期', width:80},
           {field:'company', title:'保险机构', width:80,formatter:function (value) {
                   return value.name;
               }},
           {field:'opEmployee', title:'操作人', width:80, formatter:function (value, row, index) {
                   return value.username; }}
       ]]

   });

    /*缴费处理单的弹窗*/
    $("#payBill_dialog").dialog({
        width: 350,
        height: 370,
        closed: true,
        modal: true,
        buttons: '#form_btn',
        onClose: function () {
            $("#payBill_form").form('clear');
        }
    });

    //所用的点击事件，都通过这个方法来调用对应的方法
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObject[cmd]();
    });
    //查看保单详细信息
    var methodObject = {
        show:function () {
            var row = $("#payResult_datagrid").datagrid('getSelected');
            //如果没有选择缴费处理单的一条记录
            if (row == null) {
                $.messager.alert('温馨提示', '至少选择一条记录', 'error');
                return;
            }
            //获取机构id
            if (row.company) {
                row['company.id'] = row.company.id;
            }
            //处理缴费处理单名称不回显的问题
            if (row.policyClient) {
                row['policyClient.name'] = row.policyClient.name;
            }
            if (row.company) {
                row['company.name'] = row.company.name;
            }
            $("#productInfo_datagrid").datagrid('load', {
                number: row.number
            });
            $("#payBill_form").form('load', row);
            $("#payBill_dialog").dialog('setTitle', '编辑缴费处理单');
            $("#payBill_dialog").dialog('open');
        },
        //取消按钮方法
        cancel: function () {
            $("#payBill_dialog").dialog('close');
        },
        //高级查询
        query: function () {
            var keyword = $("#keyword").textbox('getValue');
            var number = $("#number").textbox('getValue');
            var beginDate = $("#beginDate").datebox('getValue');
            var endDate = $("#endDate").datebox('getValue');
            $("#payResult_datagrid").datagrid('load', {
                keyword: keyword,
                number: number,
                beginDate:beginDate,
                endDate:endDate
            })
        },
        //刷新方法
        refresh:function () {
            $("#payResult_datagrid").datagrid('reload');
        }
    }
});